package wang.raye.gridviewanim;

import android.app.Activity;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;

public class MainActivity extends Activity {

    private ViewGroup baseLayout;
    private GridView gridView;
    private TextView testView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        gridView = (GridView) findViewById(R.id.grid);
        testView = (TextView) findViewById(R.id.test);
        baseLayout = (ViewGroup) findViewById(R.id.baseLayout);

        ArrayList<String> datas = new ArrayList<>();
        for(int i = 0; i < 30;i++){
            datas.add("postion:"+i);
        }

        gridView.setAdapter(new OneAdapter(this,datas));
    }


    public void anim(TextView v){
//        TextView temp = new TextView(this);
        int[] local = new int[2];
        v.getLocationInWindow(local);

//        temp.setLayoutParams(lp);
//        temp.setText(v.getText());
//        baseLayout.addView(temp);

        int[] toLocal = new int[2];
        testView.getLocationInWindow(toLocal);
//        local[1]-statusBarHeight toLocal[1]-statusBarHeight
        Animation animation = new TranslateAnimation(0,toLocal[0]-local[0],0,
                toLocal[1]-local[1]);
        animation.setDuration(3000);
        v.startAnimation(animation);
    }
}
